package com.uduew.sjd.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;

import androidx.constraintlayout.widget.ConstraintLayout;

import com.uduew.sjd.R;


public class EmptyView extends ConstraintLayout {
    private Context mContext;
    private OnEmptyListener mOnEmptyListener;

    public EmptyView(Context context) {
        this(context, null);
        init();
    }

    public EmptyView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
        init();
    }

    public EmptyView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        mContext = context;
        init();

    }

    private void init() {
        LayoutInflater.from(mContext).inflate(R.layout.layout_empty, this);
        View retryView = findViewById(R.id.iv);
        View clickView = findViewById(R.id.refresh);
        retryView.setOnClickListener(view -> {
            if (mOnEmptyListener != null) {
                mOnEmptyListener.onRetry();
            }
        });
        clickView.setOnClickListener(view -> {
            if (mOnEmptyListener != null) {
                mOnEmptyListener.onClick();
            }
        });
    }

    public void setOnEmptyListener(OnEmptyListener listener) {
        this.mOnEmptyListener = listener;
    }

    /**
     * 倒计时监听接口
     */
    public interface OnEmptyListener {

        void onRetry();

        void onClick();

    }

}